{include file="public/header" /}



<div class="page">
    <form id="add_form" method="post" enctype="multipart/form-data">
        <table class="ds-default-table">
            <tbody>
            <tr class="noborder">
                <td class="required w120"><label class="validation" for="tasting_title">{$Think.lang.tasting_index_title}:</label></td>
                <td class="vatop rowform"><input type="text" id="tasting_title" name="tasting_title" class="txt" value="{$tasting.tasting_title|default=''}"></td>
                <td class="vatop tips"></td>
            </tr>
            <tr class="noborder">
                <td class="required w120"><label class="validation" for="tasting_index_number">{$Think.lang.tasting_index_number}:</label></td>
                <td class="vatop rowform"><input type="text" id="tasting_index_number" name="tasting_number" class="txt" value="{$tasting.tasting_number|default='0'}"></td>
                <td class="vatop tips">{$Think.lang.tasting_index_number_tips}</td>
            </tr>
            <tr class="noborder">
                <td class="required w120"><label class="validation" for="tasting_index_price">{$Think.lang.tasting_index_price}:</label></td>
                <td class="vatop rowform"><input type="text" id="tasting_index_price" name="tasting_price" class="txt" value="{$tasting.tasting_price|default='0'}"></td>
                <td class="vatop tips">{$Think.lang.tasting_index_price_tips}</td>
            </tr>
            <tr class="noborder" >
                <td class="required" ><label class="validation" for="tasting_type">{$Think.lang.tasting_index_type}:</label></td>
                <td class="vatop rowform">
                    <select name="tasting_type" id="tasting_type">
                    <option value="1" {eq name="tasting.tasting_type" value="1" }selected{/eq}>{$Think.lang.tasting_index_type_1}</option>
                    <option value="2" {eq name="tasting.tasting_type" value="2" }selected{/eq}>{$Think.lang.tasting_index_type_2}</option>
                    </select>
                </td>
                <td class="vatop tips"></td>
            </tr>
            <tr class="noborder">
                <td class="required"><label class="validation" for="tasting_startdate">{$Think.lang.tasting_index_start}:</label></td>
                <td class="vatop rowform"><input type="text"
                                                 {if !empty($tasting['tasting_id'])}

                                                    {/if}

                    id="tasting_startdate" class="txt date" name="tasting_startdate" value="{$tasting.tasting_startdate|date='Y-m-d H:i:s',###}"/></td>
                <td class="vatop tips">{$tasting.last_tasting_enddate |default=''}</td>
            </tr>
            <tr class="noborder">
                <td class="required"><label class="validation" for="tasting_enddate">{$Think.lang.tasting_index_end}:</label></td>
                <td class="vatop rowform"><input type="text" id="tasting_enddate" {if !empty($tasting['tasting_id'])}{/if} class="txt date" name="tasting_enddate" value="{$tasting.tasting_enddate|date='Y-m-d H:i:s',###}"/></td>
                <td class="vatop tips"></td>
            </tr>
            <tr class="noborder">
                <td class="required"><label class="validation" for="tasting_banner">{$Think.lang.tasting_index_banner}:</label></td>
                <td class="vatop rowform">
                    {notempty name="$tasting.tasting_banner"}
                        {volist name="$tasting.tasting_banner" id="tasting_banner"}
                        <span class="type-file-show">
                            <img class="show_image" src="{$Think.ADMIN_SITE_ROOT}/images/preview.png"/>
                            <div class="type-file-preview"><img src="{$tasting_banner}" onload="javascript:ResizeImage(this,500,500);"></div>
                        </span>
                        {/volist}
                    {/notempty}
                    <span class="type-file-box">
                        <input name="tasting_banner[]" type="file" multiple="multiple" class="type-file-file" id="tasting_banner" size="30" hidefocus="true">
                        <input type='text' name='textfield' id='textfield1' class='type-file-text' />
                        <input type='button' name='button' id='button1' value='' class='type-file-button' />
                    </span>
                </td>
                <td class="vatop tips">{$Think.lang.tasting_new_banner_tip}</td>
            </tr>
            <tr class="noborder">
                <td class="required"><label for="tasting_desc">{$Think.lang.tasting_new_desc}:</label></td>
                <td class="vatop rowform"><textarea name="tasting_desc" rows="6" class="tarea" id="tasting_desc">{:nl2br($tasting.tasting_desc)}</textarea></td>
                <td class="vatop tips"></td>
            </tr>
            <tr class="noborder">
                <td class="required"><label for="tasting_sort">{$Think.lang.tasting_openstate}:</label></td>
                <td class="vatop rowform onoff">
                    <label for="tasting_state1" class="cb-enable {eq name='tasting.tasting_state' value='1'}selected{/eq}"><span>{$Think.lang.tasting_openstate_open}</span></label>
                    <label for="tasting_state0" class="cb-disable {eq name='tasting.tasting_state' value='0'}selected{/eq}"><span>{$Think.lang.tasting_openstate_close}</span></label>
                    <input id="tasting_state1" name="tasting_state" checked="checked" value="1" type="radio">
                    <input id="tasting_state0" name="tasting_state" value="0" type="radio">
                </td>
                <td class="vatop tips"></td>
            </tr>
            </tbody>
            <tfoot>
            <tr class="tfoot">
                <td colspan="2"><a href="JavaScript:void(0);" class="btn" id="submitBtn"><span>{$Think.lang.ds_submit}</span></a></td>
            </tr>
            </tfoot>
        </table>
    </form>

</div>
<link rel="stylesheet" href="{$Think.PLUGINS_SITE_ROOT}/js/jquery-ui-timepicker/jquery-ui-timepicker-addon.min.css">
<script src="{$Think.PLUGINS_SITE_ROOT}/js/jquery-ui-timepicker/jquery-ui-timepicker-addon.min.js"></script>
<script src="{$Think.PLUGINS_SITE_ROOT}/js/jquery-ui-timepicker/i18n/jquery-ui-timepicker-zh-CN.js"></script>
<script>
    //按钮先执行验证再提交表单
    $(function () {
        jQuery.validator.methods.compareDate = function(value, element, param) {
            //var startDate = jQuery(param).val() + ":00";补全yyyy-MM-dd HH:mm:ss格式
            //value = value + ":00";
            console.log(param)
            var startDate = jQuery(param).val();

            var date1 = new Date(Date.parse(startDate.replace("-", "/")));
            var date2 = new Date(Date.parse(value.replace("-", "/")));
            console.log(date1)
            console.log(date2)
            console.log(value)


            return date1 < date2;
        };


        $("#submitBtn").click(function () {
            if ($("#add_form").valid()) {
                $("#add_form").submit();
            }
        });
    });
    $(document).ready(function () {
        $("#tasting_startdate").datetimepicker({dateFormat: 'yy-mm-dd'});
        $("#tasting_enddate").datetimepicker({dateFormat: 'yy-mm-dd'});
        $("#add_form").validate({
            errorPlacement: function (error, element) {
                error.appendTo(element.parent().parent().find('td:last'));
            },
            rules: {
                tasting_title: {
                    required: true
                },
                tasting_startdate: {
                    required: true,
                    date: false
                },
                tasting_enddate: {
                    required: true,
                    date: false,
                    compareDate:"#tasting_startdate"

                },
                tasting_sort: {
                    required: true,
                    min: 0,
                    max: 255
                }
            },
            messages: {
                tasting_title: {
                    required: '{$Think.lang.tasting_new_title_null}'
                },
                tasting_startdate: {
                    required: '{$Think.lang.tasting_new_startdate_null}'
                },
                tasting_enddate: {
                    required: '{$Think.lang.tasting_new_enddate_null}',
                    compareDate: "注意，结束日期必须大于开始日期!"
                },
                tasting_sort: {
                    required: '{$Think.lang.tasting_new_sort_null}',
                    min: '{$Think.lang.tasting_new_sort_minerror}',
                    max: '{$Think.lang.tasting_new_sort_maxerror}'
                }
            }
        });
    });

    $(function () {
        $("#tasting_banner").change(function () {
            $("#textfield1").val($("#tasting_banner").val());
        });
    });
</script>